let mongoose = require("./db")
// 定义商品类别表
let CateSchema = new mongoose.Schema({
    name: String,
    img: String,
})
// 商品分类列表作为一级分类列表，商品表中自带二级分类
let GoodSchema = new mongoose.Schema({
    // 商品名称
    name: String,
    // 商品价格
    price: Number,
    // 商品图片
    img: String,
    // 商品描述
    desc: String,
    // 商品类别
    cate: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'Cate'
    },
    // 商品销量
    salesnum: Number,
    // 商品轮播图图片
    gallery: Array,
    //商品评论，里面放用户评论信息,在数组中可以存放用户id，用户评论，发布时间
    comments: Array,
    // 商品规格   （kg 、盒）
    specTitle: String,
    // 商品二级分类
    subCategory: String,
    // 活动专区,可选可不选，默认米面杂粮
    activity: {
        type: String,
        default: ''
    },
    // 商品是否上架
    isSale: {
        type: Boolean,
        default: true
    }
})

// 订单库
const orderSchema = new mongoose.Schema({
    order_id: String,           //订单号(随机生成)
    order_price: Number,        //商品总价格
    order_img: Array,           //商品图片数组
    order_num: Number,          //商品数量
    order_time: String,         //下单时间
    order_status: Number,       //订单状态(0:未支付,1:已支付,2:已发货,3:已收货,4:已取消)
    order_address: String,      //收货地址
    order_phone: String,        //收货人电话
    userid: String,
    shopArr:Array
})

const orderModel = mongoose.model('order', orderSchema, 'order')

// 购物车
let shoppcarSchema = new mongoose.Schema({
    name: String,
    price: String,
    buynum: Number,
    maxbuy: Number,
    mess: String,
    img: String,
    flag: Boolean,
    uid: String,
    shoppid:String
})




let ShoppcarModel = mongoose.model("shoppcar", shoppcarSchema, "shoppcar")

let CateModel = mongoose.model('Cate', CateSchema, "Cate");
let GoodModel = mongoose.model('Good', GoodSchema, "Good");

module.exports = {
    CateModel,
    GoodModel,
    ShoppcarModel,
    orderModel
}

